package zhcms.admin;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class GyUserLoginValidate {
	
		public GyUserLoginValidate()
		{
			
		}
		
		public int UserLoginValidate(HttpServletRequest request, HttpServletResponse response)
		{
			int returni=0;
			//登陆判断
			Cookie[] cookies = request.getCookies();
			
			String cookieadminname=null;
			String cookieadminid=null;
			
			for(int n=0;n<cookies.length;n++)
			{
				if(cookies[n].getName().equals("adminname"))
				{
					cookieadminname=cookies[n].getValue();
				}
				if(cookies[n].getName().equals("adminid"))
				{
					cookieadminid=cookies[n].getValue();
				}
			}
			
			String adminname = (String)request.getSession().getAttribute("adminname"); 
			if(adminname == null || adminname.length() <= 0)
			{
				//cookie
				if(cookieadminname==null || cookieadminname.length()<=0)
				{
					returni=0;
				}
				else
				{
					HttpSession session = request.getSession(); 
					session.setAttribute("adminid", cookieadminid); 
					session.setAttribute("adminname", cookieadminname); 
					returni=1;
				}
			}
			else
			{
				returni=1;
			}
			return returni;
		}

}
